{include file="header/index" /}

<div class="newContentBox">
  <div class="fixedFather">
    <div class="fix">
      编辑管理员
      <span class="newNotice"><span class="newtext">*</span>为必填项</span>
      <div class="newFixBtnBox">
        <button type="button" class="newBtnDefault newBtnGray" onclick="returnBack(this)"> <i
            class="fa fa-mail-reply"></i>返回</button>
      </div>
    </div>
  </div>
  <form action="" class="layui-form newListPart ">
    <input type="hidden" name="id" value="{$user.id}" />
    <div class="newPart">
      <div class="newTitle">
        <i class="fa fa-address-book allColor icon"></i> 基本信息
      </div>
      <div class="newContent">
        <div class="layui-form-item cover_layui_f_i">
          <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 管理员账号</label>
          <div class="layui-input-block cover_layui_i_b">
            <input id="account" type="text" name="account" value="{$user.account}" readonly="readonly"
              placeholder="输入管理员帐号" required lay-verify="required" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item cover_layui_f_i">
          <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 管理员用户组</label>
          <div class="layui-input-block cover_layui_i_b">

            <select name="groupid" id="groupid">
              <option value="">==请选择用户组==</option>
              　{foreach $auth_group as $v}
              <option value="{$v.id}" {if condition="$v['id'] eq $user['groupid']" } selected {/if}>{$v.title} </option>
                　{/foreach} </select> </div> </div> <div class="layui-form-item cover_layui_f_i">
                <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span>头像</label>
                <div class="layui-input-block cover_layui_i_b layui-upload">
                  <button type="button" class="layui-btn newBtnPrimary" id="uploadOne">选择头像</button>
                  <div class="layui-upload-list">
                    <div class="uploadImg manegImg">
                      <img height="80px" width="80px" src="{$user.avatar_imgs}" />
                      <div class="remove" onclick="removeImg(this)"><i class="fa fa-times"></i></div>
                      <input type="hidden" name="avatar_img" value="{$user.avatar_img}" />
                    </div>
                  </div>
                </div>
          </div>
          <div class="layui-form-item cover_layui_f_i">
            <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 登录密码</label>
            <div class="layui-input-block cover_layui_i_b">
              <input id="password" type="text" name="password" placeholder="输入登录密码" required lay-verify="required"
                autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item cover_layui_f_i">
            <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 真实姓名</label>
            <div class="layui-input-block cover_layui_i_b">
              <input id="name" type="text" name="name" value="{$user.name}" placeholder="输入管理员真实姓名" required
                lay-verify="required" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item cover_layui_f_i">
            <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span>手机号码</label>
            <div class="layui-input-block cover_layui_i_b">
              <input id="phone" type="text" name="phone" value="{$user.phone}" placeholder="输入管理员手机号" required
                lay-verify="required" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item cover_layui_f_i">
            <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 邮箱</label>
            <div class="layui-input-block cover_layui_i_b">
              <input id="email" type="text" name="email" value="{$user.email}" placeholder="输入管理员邮箱" required
                lay-verify="required" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item cover_layui_f_i">
            <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 联系地址</label>
            <div class="layui-input-block cover_layui_i_b">
              <input id="address" type="text" name="address" value="{$user.address}" placeholder="输入管理员联系地址" required
                lay-verify="required" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item cover_layui_f_i">
            <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span>状态</label>
            <div class="layui-input-block cover_layui_i_b">
              <input type="checkbox" name="status" value="1" lay-skin="primary" title="" {if
                condition=" $user['status'] eq 1" } checked {/if}> <span
                style="position: absolute;top: 10px;">默认开启</span>
            </div>
          </div>
        </div>
        <div class="layui-form-item ">
          <div class="layui-input-block cover_layui_i_b">
            <button class="layui-btn newBtnDefault newBtnPrimary" lay-submit lay-filter="formDemo">保存</button>
            <button type="reset" class="layui-btn newBtnDefault">重置</button>
          </div>
        </div>
      </div>
  </form>
</div>

<script type="text/javascript">
  var layer = layui.layer,
    element = layui.element,
    laydate = layui.laydate,
    laypage = layui.laypage,
    form = layui.form,
    upload = layui.upload,
    layedit = layui.layedit;
  form.render();
  //重置
  function reset() {
    top.layer.confirm('你确定要重置吗?', {
      btn: ['确定', '取消'] //按钮
    }, function () {
      $('#userAdd')[0].reset();
      top.layer.msg('重置成功', {
        icon: 1
      });
    });
  }
  // 单图头像
  var uploadOne = upload.render({
    elem: '#uploadOne',
    url: '{:url("commonapi/upload/uploadImg")}',
    done: function (res) {
      //如果上传失败
      if (res.code == -1000) {
        return layer.msg('上传失败');
      } else {
        var html = '<div class="uploadImg manegImg">' +
          '<input type="hidden" value="' + res.data.url + '" name="avatar_img">' +
          '<img src="' + res.data.all_url + '" height="80px" width="80px" alt="">' +
          '<div class="remove" onclick="removeImg(this)"><i class="fa fa-times"></i></div>' +
          '</div>'
        $("#uploadOne").siblings('.layui-upload-list').html(html);
      }
      //上传成功
    },
    error: function () {
      layer.msg('上传失败', {
        icon: 2
      })
    }
  });
  //提交表单
  var flag = false;
  form.on('submit(formDemo)', function (data) {
    if (flag) {
      return false;
    }
    flag = true;
    delete data.field.file //true
    $.post("{:url('Users/updateUser')}", data.field, function (e) {
      if (e.code == 1) {
        top.layer.msg(e.msg, {
          icon: 1,
          time: 2000
        }, function () {
          top.layer.close();
          window.location.href = e.data;
        });
      } else {
        top.layer.msg(e.msg, {
          icon: 2,
          time: 2000
        });
      }
      flag = false;
    }, 'json');
    return false;
  });
</script>